package com.wxy.web.security.authorization;

import com.wxy.common.utils.ResponseUtil;
import com.wxy.common.utils.ValidResult;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AuthEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        ValidResult validResult = new ValidResult();
        validResult.fail("", "Error", "token无效");
        ResponseUtil.write(response, HttpStatus.UNAUTHORIZED.value(), validResult);
    }
}
